package com.adou.service.impl;

import com.adou.common.mapper.FlowDirectionMapper;
import com.adou.common.mapper.FlowMainFileMapper;
import com.adou.common.model.FlowDirection;
import com.adou.common.model.FlowMainFile;
import com.adou.service.FlowDirectionService;
import com.adou.service.impl.base.BaseServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class FlowDirectionServiceImpl extends BaseServiceImp<FlowDirection> implements FlowDirectionService {

    @Autowired
    private FlowDirectionMapper flowDirectionMapper;

    @Autowired
    private FlowMainFileMapper flowMainFileMapper;

    @Override
    public int deleteBatch(List<FlowDirection> o) {
        FlowDirection flowDirection = new FlowDirection();
        FlowMainFile flowMainFile = new FlowMainFile();
        for (FlowDirection f : o ) {
            flowDirection.setId(f.getId());
            List<FlowDirection> flowDirectionList = flowDirectionMapper.find(flowDirection);
            if(flowDirectionList.size()==1){
                flowMainFile.setIfmid(flowDirectionList.get(0).getIfmid());
                List<FlowMainFile> flowMainFileList = flowMainFileMapper.find(flowMainFile);
                if(flowMainFileList.size()>0){
                    return -1;
                }
            }
        }
        return super.deleteBatch(o);
    }

}
